/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgHero
    {
        private readonly Dictionary<int, CfgHero> _dataMap;
        private readonly List<CfgHero> _dataList;


        public TbCfgHero(ByteBuf _buf)
        {
            //first read common data
            _TbCommonHero _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonHero(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgHero>(size * 3 / 2);
            _dataList = new List<CfgHero>(size);

            for (int i = 0; i < size; i++)
            {
                CfgHero _v;
                _v = CfgHero.DeserializeCfgHero(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgHero> DataMap => _dataMap;
        public IReadOnlyList<CfgHero> DataList => _dataList;

        public CfgHero Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgHero] config not found,id:" + key.ToString());

            return null;
        }

        public CfgHero GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "hero";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgHero LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgHero(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgHero
    {
        private CfgHero(ByteBuf _buf, _TbCommonHero _commonData)
        {
            Id = _buf.ReadInt();
            Name = TableCenter.GetI18NText(_buf.ReadInt());
            SoulId = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; TransItem = _commonData._field0[dataIndex]; }
            DefaultStar = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; HeroSkinIds = _commonData._field1[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; HeroSkinIds2 = _commonData._field2[dataIndex]; }
            Radius = _buf.ReadInt();
            IsHide = _buf.ReadBool();
            HeroClass = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; DefaultSkill = _commonData._field3[dataIndex]; }
            HeroElementType = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; AttType = _commonData._field4[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; AttValue = _commonData._field5[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; Diglog = _commonData._field6[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; AI = _commonData._field7[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; StarPrefab = _commonData._field8[dataIndex]; }

            PostInit();
        }

        internal static CfgHero DeserializeCfgHero(ByteBuf _buf, _TbCommonHero _commonData)
        {
            return new CfgHero(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 英雄名称
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 灵魂ID
        /// </summary>
        public int SoulId { get; private set; }
        /// <summary>
        /// 重复人偶转换碎片
        /// </summary>
        public IReadOnlyList<int> TransItem { get; private set; }
        /// <summary>
        /// 默认星级
        /// </summary>
        public int DefaultStar { get; private set; }
        /// <summary>
        /// 主角短发形态时，所有人偶可穿戴皮肤，数组第一个数据表示默认皮肤
        /// </summary>
        public IReadOnlyList<int> HeroSkinIds { get; private set; }
        /// <summary>
        /// 主角长发形态时，所有人偶可穿戴皮肤，数组第一个数据表示默认皮肤
        /// </summary>
        public IReadOnlyList<int> HeroSkinIds2 { get; private set; }
        /// <summary>
        /// 实体半径(cm)
        /// </summary>
        public int Radius { get; private set; }
        /// <summary>
        /// 是否隐藏(0显示1隐藏）
        /// </summary>
        public bool IsHide { get; private set; }
        /// <summary>
        /// 定位（1坦克 2输出 3治疗）
        /// </summary>
        public int HeroClass { get; private set; }
        /// <summary>
        /// 英雄技能ID
        /// </summary>
        public IReadOnlyList<int> DefaultSkill { get; private set; }
        /// <summary>
        /// 英雄属性分类（1物理,2魔法,3冰,4火,5雷）
        /// </summary>
        public int HeroElementType { get; private set; }
        /// <summary>
        /// 英雄初始属性1类型
        /// </summary>
        public IReadOnlyList<int> AttType { get; private set; }
        /// <summary>
        /// 生命
        /// </summary>
        public IReadOnlyList<int> AttValue { get; private set; }
        /// <summary>
        /// 大招战斗内冒字
        /// </summary>
        public string Diglog { get; private set; }
        /// <summary>
        /// AI配置
        /// </summary>
        public string AI { get; private set; }
        /// <summary>
        /// 升星星图预设
        /// </summary>
        public string StarPrefab { get; private set; }

        /// <summary>
        /// StarPrefab 资源全路径
        /// </summary>
        public string StarPrefab_fullPath => $"Res/03_Prefabs/UI/HeroEvolutionPrefab/{StarPrefab}";

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonHero
    {

        internal IReadOnlyList<IReadOnlyList<int>> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field1 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field2 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field3 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field4 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field5 { get; private set; }
        internal IReadOnlyList<string> _field6 { get; private set; }
        internal IReadOnlyList<string> _field7 { get; private set; }
        internal IReadOnlyList<string> _field8 { get; private set; }
        internal _TbCommonHero(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field4 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field5 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field6 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field7 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field8 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
        }

    }
}
